var reg1 = /0*([1-9]\d*|0\.\d+)/;
var reg2 = /(?:\.0*|(\.\d+?)0+)$/;
function showToastSuc(content){
	uni.showToast({
		title: content,
		icon: 'success',
		duration: 1800
	})
}
function showToast(content,duration){
	uni.showToast({
		title: content,
		icon: 'none',
		duration: duration == undefined ? 1800 : duration
	})
}
function setClipborarData(content){
	uni.setClipboardData({
		data:content,
		success:()=>{
			uni.showToast({
				title: '复制成功',
				icon: 'success',
				duration: 1800
			})
		}
	})
}
function comNavigateToLogin(opt,canRefreshFlag){
	uni.navigateTo({
		url:'/pages/login/login?loadOpt=' + opt + '&canRefreshFlag=' + canRefreshFlag
	})
}
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
}
function patternNum(str){
	if(str != ''){
		str = parseFloat(str.replace(reg1, '$1').replace(reg2, '$1')).toFixed(2);
	}else{
		str = 0;
	}
	return str;
}

function isEmojiCharacter(substring){
	if(substring){
		for ( var i = 0; i < substring.length; i++) {
			var hs = substring.charCodeAt(i);
			if (0xd800 <= hs && hs <= 0xdbff) {
				if (substring.length > 1) {
					var ls = substring.charCodeAt(i + 1);
					var uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
					if (0x1d000 <= uc && uc <= 0x1f77f) {
						return true;
					}
				}
			} else if (substring.length > 1) {
				var ls = substring.charCodeAt(i + 1);
				if (ls == 0x20e3) {
					return true;
				}
			} else {
				if (0x2100 <= hs && hs <= 0x27ff) {
					return true;
				} else if (0x2B05 <= hs && hs <= 0x2b07) {
					return true;
				} else if (0x2934 <= hs && hs <= 0x2935) {
					return true;
				} else if (0x3297 <= hs && hs <= 0x3299) {
					return true;
				} else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030
					|| hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b
					|| hs == 0x2b50) {
					return true;
				}
			}
		}
	}
}
function Str2Bytes(str){
	var pos = 0;
	var len = str.length;
	if(len %2 != 0)
	{
	   return null; 
	}
	len /= 2;
	var hexA = new Array();
	for(var i=0; i<len; i++)
	{
	   var s = str.substr(pos, 2);
	   var v = parseInt(s, 16);
	   if(v>=128) v = v | 0xFFFFFF00;
	   hexA.push(v);
	   pos += 2;
	}
	return hexA;
}
function appendZero(obj){
	if (obj < 10) {
	  return '0' + obj 
	} else {
	  return obj
	} 
}
function getNowTimeDay(){
	var date = new Date();
	return date.getFullYear() + '-' + appendZero((date.getMonth()+1)) + '-' + appendZero(date.getDate());
}
function getNowTimeMonth(){
	var date = new Date();
	return date.getFullYear() + '-' + appendZero((date.getMonth()+1));
}
function getNowTime(){
	let now = new Date();
	let year = now.getFullYear(); //获取完整的年份(4位,1970-????)
	let month = now.getMonth() + 1; //获取当前月份(0-11,0代表1月)
	let today = now.getDate(); //获取当前日(1-31)
	let hour = now.getHours(); //获取当前小时数(0-23)
	let minute = now.getMinutes(); //获取当前分钟数(0-59)
	let second = now.getSeconds(); //获取当前秒数(0-59)
	let nowTime = ''
	nowTime = year + '-' + appendZero(month) + '-' + appendZero(today) + ' ' + appendZero(hour) + ':' +
	  appendZero(minute) + ':' + appendZero(second)
	return nowTime
}
function fillZero(str){
	var realNum;
	if (str < 10) {
	  realNum = '0' + str;
	} else {
	  realNum = str;
	}
	return realNum;
}
function commonMultiSelect(obj,newObj,index,name){
	if(obj[index].selFlag){
		obj[index].selFlag = false;
		for(var i=0;i<newObj.length;i++){
			if(name == newObj[i]){
				newObj.splice(i,1);
			}
		}
	}else if(obj[index].selFlag == false) {
		obj[index].selFlag = true;
		newObj.push(obj[index].name)
	}
	//console.log(newObj)
}
function switchWordsToNum(str){
	let tmpIndex = -1;
	switch (str) {
		case 'A':
			tmpIndex = 0;
			break;
		case 'B':
			tmpIndex = 1;
			break;
		case 'C':
			tmpIndex = 2;
			break;
		case 'D':
			tmpIndex = 3;
			break;
		case 'E':
			tmpIndex = 4;
			break;
		case 'F':
			tmpIndex = 5;
			break;
		case 'G':
			tmpIndex = 6;
			break;
	}
	return tmpIndex;
}
function replaceToBr(str){
	return str.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
}
function getUrlParams(url){
	let arr = url.split('?');
   let params = arr[1].split('&');
   let obj = {};
   for(let i=0;i<params.length;i++){
       let param = params[i].split('=');
       obj[param[0]] = param[1];
   }
   return obj;
}

function delLastQuot(str){
	return str.substring(0,str.length - 1)
}
function addDate(date,days){
	if (days == undefined || days == '') {
		days = 1;
	}
	var date = new Date(date);
	date.setDate(date.getDate() + days);
	var month = date.getMonth() + 1;
	var day = date.getDate();
	return date.getFullYear() + '-' + getFormatDate(month) + '-' + getFormatDate(day);
}
function getFormatDate(arg){
	if (arg == undefined || arg == '') {
		return '';
	}
	var re = arg + '';
	if (re.length < 2) {
		re = '0' + re;
	}
	return re;
}
export default {
	showToastSuc,
	showToast,
	trim,
	isEmojiCharacter,
	Str2Bytes,
	patternNum,
	setClipborarData,
	comNavigateToLogin,
	commonMultiSelect,
	switchWordsToNum,
	getNowTime,
	getNowTimeDay,
	getNowTimeMonth,
	replaceToBr,
	getUrlParams,
	delLastQuot,
	addDate
}
